package netty.study.fifth;

import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;
import io.netty.handler.stream.ChunkedWriteHandler;
import io.netty.handler.timeout.IdleStateHandler;

import java.util.concurrent.TimeUnit;

/**
 * @author songZiHao
 * @version 1.0.0
 * @ClassName MyServerChannelIniltializer.java
 * @Description TODO
 * @createTime 2020年04月17日 16:57:00
 */
public class MyServerChannelInitializer extends ChannelInitializer {
	@Override
	protected void initChannel(Channel ch) throws Exception {
		ChannelPipeline pipeline = ch.pipeline();
		pipeline.addLast(new HttpServerCodec());
		pipeline.addLast(new ChunkedWriteHandler());
		//将多段的http请求段聚合成一个完整的http请求
		pipeline.addLast(new HttpObjectAggregator(8192));
		//专门处理webSocket的Handler
		pipeline.addLast(new WebSocketServerProtocolHandler("/ws"));
		pipeline.addLast(new MyServerHandler());
	}
}
